package com.hjf.service.impl;

import java.util.List;
import java.util.Map;

import com.commons.po.DeptPo;
import com.commons.po.PageBean;
import com.hjf.dao.DeptPoDao;
import com.hjf.dao.impl.DeptPoDaoImpl;
import com.hjf.service.DeptPoService;

public class DeptPoServiceImpl implements DeptPoService {
	private DeptPoDao dd=new DeptPoDaoImpl();
	@Override
	public List<DeptPo> findByCondition() {
		List<DeptPo> list=dd.findDeptAll();
		for(int i=0;i<list.size();i++){
			Integer j=list.get(i).getDeptParent();
			if(j!=null){
				List<DeptPo> list2=findById(j);
				list.get(i).setParentName(list2.get(0).getDeptName());
			}
		}
		return list;
	}

	@Override
	public List<DeptPo> findById(Integer id) {
		List<DeptPo> list=dd.findDeptById(id);
		return list;
	}

	@Override
	public int saveDeptPo(DeptPo entity) {
		return dd.saveDeptPo(entity);
	}

	@Override
	public int updateDeptPo(DeptPo entity) {
		return dd.updateDeptPo(entity);
	}

	@Override
	public List<DeptPo> findByDeptParent(Integer deptParent) {
		List<DeptPo> list=dd.findByDeptParent(deptParent);
		return list;
	}

	@Override
	public PageBean<DeptPo> findPageByCondition(int pageIndex, int pageSize, Map<String, Object> map) {
		PageBean<DeptPo> pageBean=dd.findPageByCondition(pageIndex, pageSize, map);
		List<DeptPo> list=pageBean.getList();
		if(list!=null&&list.size()>0){
			for(int i=0;i<list.size();i++){
				Integer j=list.get(i).getDeptParent();
				if(j!=null){
					List<DeptPo> list2=findById(j);
					list.get(i).setParentName(list2.get(0).getDeptName());
				}
			}
		}
		return pageBean;
	}

}
